package org.ehe.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.core.validate.AddGroup;
import org.ehe.common.core.validate.EditGroup;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.ehe.system.domain.bo.HrEmployeeAttachmentBo;
import org.ehe.system.domain.vo.HrEmployeeAttachmentVo;
import org.ehe.system.service.IHrEmployeeAttachmentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 员工附件管理
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/employee/attachment")
public class HrEmployeeAttachmentController extends BaseController {

    private final IHrEmployeeAttachmentService attachmentService;

    /**
     * 查询员工附件列表
     */
    @SaCheckPermission("system:employee:list")
    @GetMapping("/list")
    public TableDataInfo<HrEmployeeAttachmentVo> list(HrEmployeeAttachmentBo bo, PageQuery pageQuery) {
        return attachmentService.queryPageList(bo, pageQuery);
    }

    /**
     * 根据工号查询员工附件列表
     *
     * @param employeeNo 工号
     */
    @SaCheckPermission("system:employee:query")
    @GetMapping("/list/{employeeNo}")
    public R<List<HrEmployeeAttachmentVo>> listByEmployeeNo(@PathVariable String employeeNo) {
        return R.ok(attachmentService.queryListByEmployeeNo(employeeNo));
    }

    /**
     * 获取员工附件详细信息
     *
     * @param attachmentId 附件主键
     */
    @SaCheckPermission("system:employee:query")
    @GetMapping("/{attachmentId}")
    public R<HrEmployeeAttachmentVo> getInfo(@PathVariable Long attachmentId) {
        return R.ok(attachmentService.queryById(attachmentId));
    }

    /**
     * 新增员工附件
     */
    @SaCheckPermission("system:employee:add")
    @Log(title = "员工附件", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HrEmployeeAttachmentBo bo) {
        return toAjax(attachmentService.insertByBo(bo));
    }

    /**
     * 修改员工附件
     */
    @SaCheckPermission("system:employee:edit")
    @Log(title = "员工附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HrEmployeeAttachmentBo bo) {
        return toAjax(attachmentService.updateByBo(bo));
    }

    /**
     * 删除员工附件
     *
     * @param attachmentIds 附件主键串
     */
    @SaCheckPermission("system:employee:remove")
    @Log(title = "员工附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{attachmentIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] attachmentIds) {
        return toAjax(attachmentService.deleteByIds(Arrays.asList(attachmentIds)));
    }

}
